#!/bin/bash

# postinst script for system-io-tests
#
# see: dh_installdeb(1)

#set -e

# summary of how this script can be called:
#        * <postinst> \`configure' <most-recently-configured-version>
#        * <old-postinst> \`abort-upgrade' <new version>
#        * <conflictor's-postinst> \`abort-remove' \`in-favour' <package>
#          <new-version>
#        * <postinst> \`abort-remove'
#        * <deconfigured's-postinst> \`abort-deconfigure' \`in-favour'
#          <failed-install-package> <version> \`removing'
#          <conflicting-package> <version>
# for details, see http://www.debian.org/doc/debian-policy/ or
# the debian-policy package

PATH=/usr/bin:/sbin:/usr/sbin:/usr/local/bin:/usr/local/sbin
export PATH

if [ "${BASEDIR:=/}" = "/" ]; then
    BASEDIR=""
else
    BASEDIR_OPT="-b $BASEDIR"
fi

case "$1" in
    configure)
        chmod 0555 "$BASEDIR/usr/lib/scsi/sestopo"
	chown root:bin "$BASEDIR/usr/lib/scsi/sestopo"
	chmod 0555 "$BASEDIR/usr/lib/scsi/smp"
	chown root:bin "$BASEDIR/usr/lib/scsi/smp"
	chmod 0555 "$BASEDIR/usr/sbin/devctl"
	chown root:bin "$BASEDIR/usr/sbin/devctl"
	chmod 0555 "$BASEDIR/usr/sbin/emul64ioctl"
	chown root:bin "$BASEDIR/usr/sbin/emul64ioctl"
	if [ "$ZONEINST" = "1" ]; then
	    [ -f $BASEDIR/usr/kernel/drv/emul64.conf ] && rm -f $BASEDIR/usr/kernel/drv/emul64.conf
	else
	    chmod 0644 "$BASEDIR/usr/kernel/drv/emul64.conf"
	    chown root:sys "$BASEDIR/usr/kernel/drv/emul64.conf"
	fi
	if [ "$ZONEINST" = "1" ]; then
	    [ -f $BASEDIR/usr/kernel/drv/pshot.conf ] && rm -f $BASEDIR/usr/kernel/drv/pshot.conf
	else
	    chmod 0644 "$BASEDIR/usr/kernel/drv/pshot.conf"
	    chown root:sys "$BASEDIR/usr/kernel/drv/pshot.conf"
	fi
	if [ "$ZONEINST" = "1" ]; then
	    [ -f $BASEDIR/usr/kernel/drv/ufmtest.conf ] && rm -f $BASEDIR/usr/kernel/drv/ufmtest.conf
	else
	    chmod 0644 "$BASEDIR/usr/kernel/drv/ufmtest.conf"
	    chown root:sys "$BASEDIR/usr/kernel/drv/ufmtest.conf"
	fi
	if [ "$ZONEINST" = "1" ]; then
	    [ -f $BASEDIR/usr/kernel/drv/amd64/emul64 ] && rm -f $BASEDIR/usr/kernel/drv/amd64/emul64
	else
	    chmod 0755 "$BASEDIR/usr/kernel/drv/amd64/emul64"
	    chown root:sys "$BASEDIR/usr/kernel/drv/amd64/emul64"
	fi
	if [ "$ZONEINST" = "1" ]; then
	    [ -f $BASEDIR/usr/kernel/drv/amd64/gen_drv ] && rm -f $BASEDIR/usr/kernel/drv/amd64/gen_drv
	else
	    chmod 0755 "$BASEDIR/usr/kernel/drv/amd64/gen_drv"
	    chown root:sys "$BASEDIR/usr/kernel/drv/amd64/gen_drv"
	fi
	if [ "$ZONEINST" = "1" ]; then
	    [ -f $BASEDIR/usr/kernel/drv/amd64/pshot ] && rm -f $BASEDIR/usr/kernel/drv/amd64/pshot
	else
	    chmod 0755 "$BASEDIR/usr/kernel/drv/amd64/pshot"
	    chown root:sys "$BASEDIR/usr/kernel/drv/amd64/pshot"
	fi
	if [ "$ZONEINST" = "1" ]; then
	    [ -f $BASEDIR/usr/kernel/drv/amd64/tclient ] && rm -f $BASEDIR/usr/kernel/drv/amd64/tclient
	else
	    chmod 0755 "$BASEDIR/usr/kernel/drv/amd64/tclient"
	    chown root:sys "$BASEDIR/usr/kernel/drv/amd64/tclient"
	fi
	if [ "$ZONEINST" = "1" ]; then
	    [ -f $BASEDIR/usr/kernel/drv/amd64/tphci ] && rm -f $BASEDIR/usr/kernel/drv/amd64/tphci
	else
	    chmod 0755 "$BASEDIR/usr/kernel/drv/amd64/tphci"
	    chown root:sys "$BASEDIR/usr/kernel/drv/amd64/tphci"
	fi
	if [ "$ZONEINST" = "1" ]; then
	    [ -f $BASEDIR/usr/kernel/drv/amd64/tvhci ] && rm -f $BASEDIR/usr/kernel/drv/amd64/tvhci
	else
	    chmod 0755 "$BASEDIR/usr/kernel/drv/amd64/tvhci"
	    chown root:sys "$BASEDIR/usr/kernel/drv/amd64/tvhci"
	fi
	if [ "$ZONEINST" = "1" ]; then
	    [ -f $BASEDIR/usr/kernel/drv/amd64/ufmtest ] && rm -f $BASEDIR/usr/kernel/drv/amd64/ufmtest
	else
	    chmod 0755 "$BASEDIR/usr/kernel/drv/amd64/ufmtest"
	    chown root:sys "$BASEDIR/usr/kernel/drv/amd64/ufmtest"
	fi
    ;;

    abort-upgrade|abort-remove|abort-deconfigure)
    ;;

    *)
        echo "postinst called with unknown argument '$1'" >&2
        exit 1
    ;;
esac



# dh_installdeb will replace this with shell code automatically
# generated by other debhelper scripts.

#DEBHELPER#

exit 0

